% function of convlution encoder
% 1 bit in, 2 bit out (2,1,4)
% input: the input sequence
% g1 : [ 1 0 1 1]
% g2 : [1 1 1 1]
function output = conv_encode(input, g1, g2)
	K = length(g1);
	input_len = length(input);
	temp = zeros(2,length(input)+K-1);
	mem = zeros(1,K); % when the mem be 0, the output end
	for i = 1: (input_len + K -1)

        mem(4) = mem(3);
		mem(3) = mem(2);
		mem(2) = mem(1);
        if (i > input_len)
            input(i) = 0;
        end
		mem(1) = input(i);
        
        temp(1, i) = mod(sum(g1.*mem), 2);
		temp(2, i) = mod(sum(g2.*mem), 2);
    end
    
    output = reshape(temp, 1, numel(temp));
    
    
    

